package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.sun.org.apache.regexp.internal.RE;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.*;

class ErChaSouSuoShuDeDiKdaJieDianLcof {
    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode(int x) { val = x; }
     * }
     */
    class Solution {
        int res;
        int index = 0; //计数器

        public int kthLargest(TreeNode root, int k) {
            dfs(root, k);
            return res;
        }

        void dfs(TreeNode root, int k) {
            if (root == null) return;
            dfs(root.right, k); //右
            index++;
            if (k == index) res = root.val; //根
            dfs(root.left, k); //左
        }

    }
//leetcode submit region end(Prohibit modification and deletion)

}

